package com.whfc.wxmp.api.mach.v1.service.impl;

import com.whfc.common.result.ListData;
import com.whfc.common.result.PageData;
import com.whfc.common.result.PageVO;
import com.whfc.common.util.DateUtil;
import com.whfc.fuum.service.SysDeptService;
import com.whfc.fuum.service.SysMachTypeService;
import com.whfc.mach.dto.*;
import com.whfc.mach.param.MachPageDataQueryParam;
import com.whfc.mach.param.MachQueryParam;
import com.whfc.mach.service.AppMachDataService;
import com.whfc.wxmp.api.mach.v1.service.WxmpMachDataService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author sun_guodong
 * @description
 * @date 2020-11-17
 */
@Service
public class WxmpMachDataServiceImpl implements WxmpMachDataService {

    @DubboReference(interfaceClass = SysMachTypeService.class, version = "1.0.0")
    private SysMachTypeService sysMachTypeService;

    @DubboReference(interfaceClass = SysDeptService.class, version = "1.0.0")
    private SysDeptService sysDeptService;

    @DubboReference(interfaceClass = AppMachDataService.class, version = "1.0.0")
    private AppMachDataService appMachDataService;

    @Override
    public MapMachDTO mapList(MachQueryParam param) {
        Integer deptId = param.getDeptId();
        List<Integer> corpIds = param.getCorpIds();
        List<Integer> machTypeIds = param.getMachTypeIds();
        List<Integer> deptIds = sysDeptService.getDescendantDeptIdList(deptId);
        MapMachDTO data = appMachDataService.getMapList(deptId, deptIds, corpIds, machTypeIds, null);
        return data;
    }

    @Override
    public PageData<AppMachDTO> list(MachPageDataQueryParam param) {
        List<Integer> deptIds = sysDeptService.getDescendantDeptIdList(param.getDeptId());
        param.setDeptIds(deptIds);
        PageData<AppMachDTO> pageData = appMachDataService.getWxMachList(param);
        return pageData;
    }

    @Override
    public ListData<AppMachDTO> list(MachQueryParam param) {
        List<Integer> deptIds = sysDeptService.getDescendantDeptIdList(param.getDeptId());
        param.setDeptIds(deptIds);
        List<AppMachDTO> list = appMachDataService.getWxMachList(param);
        for (AppMachDTO machDTO : list) {
            String icon = sysMachTypeService.getIcon(machDTO.getMachType(), machDTO.getNetState(), machDTO.getWorkState());
            machDTO.setIcon(icon);
        }
        return new ListData<>(list);
    }

    @Override
    public MachDataStatDTO machNumstatic(MachQueryParam param) {
        List<Integer> deptIds = sysDeptService.getDescendantDeptIdList(param.getDeptId());
        param.setDeptIds(deptIds);
        return appMachDataService.machNumstatic(param);
    }

    @Override
    public AppMachWorkHourDayDTO getMachWorkHourDayData(Integer machId, Date date) {
        if (date == null) {
            date = DateUtil.getDate(new Date());
        }
        return appMachDataService.getMachWorkHourDayData(machId, date);
    }

    @Override
    public MachRadarMapDTO getSingleRardarMap(Integer machId, Date date) {
        if (date == null) {
            date = DateUtil.getDateBegin(new Date());
        }
        return appMachDataService.getSingleRardarMap(machId, date, date);
    }

    @Override
    public ListData<MachCurveMapDayDTO> getMachWeekData(Integer machId, Date date) {
        // 时间
        Date today = DateUtil.getDateBegin(date);
        Date startDate = DateUtil.addDays(today, -7);
        Date endDate = DateUtil.addDays(today, -1);
        return appMachDataService.getSingleMachCurveMapDayList(machId, startDate, endDate);
    }

    @Override
    public Oil getRemainOil(Integer machId) {
        return appMachDataService.getRemainOil(machId);
    }

    @Override
    public AppMachGpsDTO gpsLog(Integer machId, Date date) {
        return appMachDataService.gpsLog(machId, date);
    }

    @Override
    public Gps gpsLatest(Integer machId) {
        return appMachDataService.gpsLatest(machId);
    }

    @Override
    public MachRadarMapDTO getMultiRardarMap(Integer deptId) {
        List<Integer> deptIds = sysDeptService.getDescendantDeptIdList(deptId);
        return appMachDataService.getMultiRardarMap(deptIds);
    }

    @Override
    public MachCurveMapDTO getMultiCurveMap(Integer deptId) {
        List<Integer> deptIds = sysDeptService.getDescendantDeptIdList(deptId);
        return appMachDataService.getMultiCurveMap(deptIds);
    }

    @Override
    public MachRunDataDTO getDayOilData(Integer machId, Date date) {
        MachRunDataDTO oilData = appMachDataService.getOilData(machId, date, date);
        oilData.setDayOilList(null);
        return oilData;
    }


    @Override
    public PageData<AppMachDataLogDTO> gpsLogPage(Integer machId, Date date, Integer pageNum, Integer pageSize) {
        return appMachDataService.gpsLogPage(machId, date,pageNum,pageSize);
    }

}
